<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['hdps']=$basic['hdps'];
if($_RQ['op']=='main'){
	$bodyid=intval($_RQ['id']);
	$return['item']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
	if($return['item']['groupid']){
		$return['item']['group']=pdo_getcolumn('core_member_groups',array('id'=>$return['item']['groupid'],'uniacid'=>$_SESSION['uniacid']),'title');
	}else{
		$return['item']['group']='普通会员';
	}
	$user=pdo_get('jy_yiliao_user',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$user['mobile']=$user['mobile']?:$return['item']['mobile'];
	$return['labels']=pdo_getall('jy_yiliao_label_b',array('type'=>array(0,2),'uniacid'=>$_SESSION['uniacid']));
	$return['labels1']=pdo_getall('jy_yiliao_label_b',array('type'=>1,'uniacid'=>$_SESSION['uniacid']));
	$return['labels2']=pdo_getall('jy_yiliao_label_b',array('type'=>2,'uniacid'=>$_SESSION['uniacid']));
	$return['labels3']=pdo_getall('jy_yiliao_label_b',array('type'=>3,'uniacid'=>$_SESSION['uniacid']));
	$return['params']=array('type'=>0);
	$body=pdo_get('jy_yiliao_body',array('id'=>$bodyid,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$body['data']=json_decode($body['data'],true);
	$body['jianli']=json_decode($body['jianli'],true);
	$body['year']=date('Y',$body['agetime']);
	$body['year']=$body['year']>0?date('Y')-$body['year']:'无';
	$body['sex']=$body['sex']==1?'男':'女';
	$user=pdo_get('jy_yiliao_user',array('mid'=>$body['mid'],'uniacid'=>$_SESSION['uniacid']));
	$body['mobile']=$body['mobile']?:$user['mobile'];
	$return['post']=$body['data'];
	$return['post']['bodyid']=$body['id'];
	$return['body']=$body;
	$return['addjianli']=array('bodyid'=>$body['id']);
	set_html('title','看诊记录');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	//排序老师
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['status']=0;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>'isfa desc, id desc',
	);
	$list=pdo_getslice('jy_yiliao_body',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$sum=0;
	if($list){
		$sum=count($list);
		foreach($list as &$item){		
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['xuestatus']=$item['agetime']>TIMESTAMP?:false;
			$item['year']=date('Y',$item['agetime']);
			$item['year']=$item['year']>0?date('Y')-$item['year']:'无';
			$item['sex']=$item['sex']==1?'男':'女';
			$user=pdo_get('jy_yiliao_user',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$item['mobile']=$item['mobile']?:$user['mobile'];
		}
	}
	$return['list']=$list;
	$return['sum']=$sum;
	set_html('title','家人列表');
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	$return['item']=pdo_get('jy_yiliao_body',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$return['item']['statustitle']=$this->order_status[$return['item']['status']];
	$return['item']['createtime']=date('Y-m-d H:i:s',$return['item']['createtime']);
	set_html('title','家人详情');
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_yiliao_body',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['bodyid']){
		exi('请选择家人！','error');
	}
	$data =array(
		'data'=>ijson_encode($postdata),
	);
	pdo_update('jy_yiliao_body',$data,array('id'=>$postdata['bodyid'],'uniacid'=>$_SESSION['uniacid']));
	exi('保存成功','','jy_yiliao/home//');
}
if($_RQ['op']=='addjianli'){
	$postdata=get_postdata();
	if(!$postdata['bodyid']){
		exi('请选择家人！','error');
	}
	$body=pdo_get('jy_yiliao_body',array('id'=>$postdata['bodyid'],'uniacid'=>$_SESSION['uniacid']));
	$body['jianli']=json_decode($body['jianli'],true);
	$body['jianli'][]=$postdata;
	$data =array(
		'jianli'=>ijson_encode($body['jianli']),
	);
	pdo_update('jy_yiliao_body',$data,array('id'=>$postdata['bodyid'],'uniacid'=>$_SESSION['uniacid']));
	exi('保存成功','','jy_yiliao/home//');
}
